<template>
  <div class="employee-container">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item >首页</el-breadcrumb-item>
        <el-breadcrumb-item>人员信息管理</el-breadcrumb-item>
        <el-breadcrumb-item>公司职员管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <br>
    <el-row>
      <el-form label-width="80px">
          <el-col :span="8">
            <el-form-item label="姓名" label-width="80px">
              <el-input class="input" filterable placeholder="请输入查找的姓名"></el-input>
            </el-form-item>
          </el-col>
          <el-col span="8">
            <el-form-item label="年龄" label-width="80px">
              <el-input class="input" filterable placeholder="请输入查找的年龄"></el-input>
            </el-form-item>
          </el-col>
          <el-form-item>
            <el-button class="button_check" icon="el-icon-search">搜索</el-button>
          </el-form-item>
      </el-form>
    </el-row>
    <el-row>
      <div>
        <el-button-group style="margin-left: 20px">
          <el-button @click="btnAddClick" type="primary" icon="el-icon-edit">添加</el-button>
          <el-button type="primary" icon="el-icon-share">修改</el-button>
          <el-button class="button_" icon="el-icon-delete">删除</el-button>
        </el-button-group>
      </div>
      <el-table
        :data="tableData"
        border
        stripe
        style="width: 100%">
        <el-table-column
          prop="name"
          label="姓名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="age"
          label="年龄"
          sortable>
        </el-table-column>
        <el-table-column
          prop="gender"
          label="性别">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址">
        </el-table-column>
      </el-table>
      <el-pagination
        small
        layout="prev,pager,next"
        :total="50">
      </el-pagination>
    </el-row>
    <el-dialog
      title="员工添加"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form>
        <el-form-group>
          <el-form-item label-width="80px" label="姓名">
            <el-input v-model="employee.name"/>
          </el-form-item>
          <el-form-item label-width="80px" label="年龄">

            <el-input v-model="employee.age"/>
            </el-form-item>
            <el-form-item label-width="80px" label="性别">
              <el-select v-model="employee.gender" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label-width="80px" label="地址">
              <el-input v-model="employee.address"/>
          </el-form-item>
        </el-form-group>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible=false">取消</el-button>
          <el-button type="primary" @click="sumbmitHandle">确定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "Employee",
    data(){
      return{
        tableData:[],
        dialogVisible:false,
        employee:{
          name: '',
          age:'',
          address:'',
          gender:''
        },
        options: [{
          value: '选项1',
          label: 'male'
        }, {
          value: '选项2',
          label: 'female'
        }],
        value: ''
      }

    },mounted(){
      var _this=this;
      this.axios(
        {
          url:'http://localhost:3000/employee/emp',
          method:'get'
        }
      ).then(function (res) {
        _this.tableData=res.data;
      })
    },methods:{
      btnAddClick(){
        this.dialogVisible=true;
      },
      handleClose(){
        this.dialogVisible=false;
      },sumbmitHandle(){
        var _this=this;
        this.axios({
          url:'http://127.0.0.1:3000/employee/emp_add',
          method:'get',
          params:{
            name:this.employee.name,
            age:this.employee.age,
            gender:this.employee.gender,
            address:this.employee.address
          }
        }).then(function (res) {
          if(res.data.flag){
            _this.tableData=res.data.emps;
            _this.$message('添加成功')
            _this.dialogVisible=false;
          }else{
            alert('添加失败');
          }

        })
      }
    }

  }

</script>
<style scoped>
  .button_check{
    background-color: pink;
    margin-left: 25px;
  }
  .input{
    width: 200px
  }
  .button_{
    background-color: rgb(255,255,255);
  }
</style>


